package com.zhuhuix.startup;

import com.zhuhuix.startup.security.rest.AccessToken;
import com.zhuhuix.startup.security.rest.AccessTokenFactory;
import com.zhuhuix.startup.security.security.JwtAuthenticationTokenFilter;
import com.zhuhuix.startup.utils.SpringContextHolder;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * Springboot启动类
 * @author zhuhuix
 * @date 2020-03-01
 */
@EnableAsync
@SpringBootApplication
@EnableTransactionManagement
public class Application implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public SpringContextHolder springContextHolder() {
        return new SpringContextHolder();
    }

    @Bean
    public FilterRegistrationBean<JwtAuthenticationTokenFilter> registration(JwtAuthenticationTokenFilter filter) {
        FilterRegistrationBean<JwtAuthenticationTokenFilter> registration = new FilterRegistrationBean<>(filter);
        registration.setEnabled(false);
        return registration;
    }

    @Override
    public void run(String... args) throws Exception {
        AccessToken token =  AccessTokenFactory.getInstance();
        System.out.println(token);
        System.out.println(AccessTokenFactory.getAPPID());
        AccessTokenFactory.getMiniQr("llk");
    }
}
